package com.zyf.pattern.prototype.deep;

import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream;

import java.io.*;
import java.util.Date;

/**
 * 齐天大圣
 * create by yifeng
 */
public class QiTDS extends Monkey implements Cloneable, Serializable {
    public QiTDS() {
        this.birthday = new Date();
        this.jgb = new JGB();
    }

    public JGB jgb;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public Object deepClone() {
        try {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(bos);
            oos.writeObject(this);

            ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
            ObjectInputStream ois = new ObjectInputStream(bis);

            QiTDS copy = (QiTDS) ois.readObject();
            copy.birthday = new Date();
            return copy;
        }catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
